﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class KY_NANG_THDAO:IData<KY_NANG_TH> 
 	{
		public KY_NANG_THDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref KY_NANG_TH item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + KY_NANG_TH.c_ID;
			 p.Value = item.ID;
			 Object obj = item.ID; 
			int i = connec.ExecuteNonQuery("sp_KY_NANG_TH", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + KY_NANG_TH.c_TEN, item.TEN), new SqlParameter("@" + KY_NANG_TH.c_MOTAKN, item.MOTAKN),
				 new SqlParameter("@" + KY_NANG_TH.c_MUCDO, item.MUCDO), new SqlParameter("@" + KY_NANG_TH.c_CHUNG_CHI, item.CHUNG_CHI),
				 new SqlParameter("@" + KY_NANG_TH.c_NOICAP, item.NOICAP));
			if(t == 0)
				item.ID = Convert.ToInt64(obj);
			return i;
		}

		public override KY_NANG_TH GetItem(IDataReader dr)
		{
			KY_NANG_TH obj = new KY_NANG_TH();
			obj.ID = Convert.ToInt64(dr[KY_NANG_TH.c_ID]);
			obj.TEN = Convert.ToString(dr[KY_NANG_TH.c_TEN]);
			obj.MOTAKN = Convert.ToString(dr[KY_NANG_TH.c_MOTAKN]);
			obj.MUCDO = Convert.ToString(dr[KY_NANG_TH.c_MUCDO]);
			obj.CHUNG_CHI = Convert.ToString(dr[KY_NANG_TH.c_CHUNG_CHI]);
			obj.NOICAP = Convert.ToString(dr[KY_NANG_TH.c_NOICAP]);
			return obj;
		}

		public override List<KY_NANG_TH> GetAll()
		{
			return GetAll("sp_GetAllKY_NANG_TH", CommandType.StoredProcedure);
		}

		public override KY_NANG_TH GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.ID == Convert.ToInt64(id));
		}
		public override KY_NANG_TH GetItemById(KY_NANG_TH item){
			throw new NotImplementedException();
		}

	}

 }
